<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.11"/>
<title>GrPPI: Map pattern</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { init_search(); });
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="logo.svg"/></td>
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">GrPPI
   &#160;<span id="projectnumber">0.2</span>
   </div>
   <div id="projectbrief">Generic and Reusable Parallel Pattern Interface</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.11 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li class="current"><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">Map pattern </div>  </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p>The <b>map</b> pattern applies an operation to every element in one or multiple data sets, generating a new data set as an output.</p>
<p>The interface to the <b>map</b> pattern is provided by function <code><a class="el" href="group__map__pattern__native.html#ga219611f3c6719598a8810d6ea6cafe2a" title="Invoke Map pattern on a data sequence with native paralell execution. ">grppi::map()</a></code>. As all functions in <em>GrPPI</em>, this function takes as its first argument an execution policy.</p>
<div class="fragment"><div class="line"><a class="code" href="group__map__pattern__native.html#ga219611f3c6719598a8810d6ea6cafe2a">grppi::map</a>(exec, other_arguments...);</div></div><!-- fragment --><h2>Map variants</h2>
<p>There are several variants:</p>
<ul>
<li><em>Unary map</em>: A map taking a single input sequence.</li>
<li><em>N-ary map</em>: A map taking multiple input sequences.</li>
</ul>
<h2>Key elements in a map</h2>
<p>The key element in a <b>map</b> pattern is the <b>Transformer</b> operation.</p>
<p>The transformer may be a <b>UnaryTransformer</b> or a <b>MultiTransformer</b>.</p>
<p>A <b>UnaryTransformer</b> is any C++ callable entity that takes a data item and transforms it. The input type and the output type may differ. Thus, a unary transformer <code>op</code> is any operation that, given an input <code>x</code> of type <code>T</code> and output type <code>U</code>, makes valid the following:</p>
<div class="fragment"><div class="line">U res = op(x);</div></div><!-- fragment --><p>A <b>MultiTransformer</b> is any C++ callable entity that takes data items, one of each input sequence, and transforms them into an output value. The input types and the output type may differ. Thus, a multi-transformer <code>op</code> is any operation that, given inputs <code>x1, x2, ... , xN</code> of types <code>T1, T2, ... , TN</code> and an output type <code>U</code>, makes valid the following:</p>
<div class="fragment"><div class="line">U res = op(x1,x2,...,xN)</div></div><!-- fragment --><h2>Details on map variants</h2>
<h3>Unary map</h3>
<p>An unary <b>map</b> takes a data set and transforms each element in the data set by applying an unary function and generating a new data set.</p>
<p>The only interface currently offered for this pattern is based in iterators (following the C++ standard library conventions):</p>
<ul>
<li>The input data set is specified by two iterators.</li>
<li>The output data set is specified by an iterator to the start of the output sequence. <hr/>
 <b>Example</b>: Doubling values in a vector. <div class="fragment"><div class="line">vector&lt;double&gt; v = get_the_vector();</div><div class="line">vector&lt;double&gt; w(v.size());</div><div class="line"><a class="code" href="group__map__pattern__native.html#ga219611f3c6719598a8810d6ea6cafe2a">map</a>(exec, begin(v), end(v), begin(w),</div><div class="line">    [](<span class="keywordtype">double</span> x) { <span class="keywordflow">return</span> 2 *x; }</div><div class="line">);</div></div><!-- fragment --><hr/>
</li>
</ul>
<h3>N-ary map</h3>
<p>A n-ary <b>map</b> takes multiple data sets and transforms a tuple of elements from those data sets by applying a n-ary function and generating a new data set.</p>
<p>The only interface currently offered for this pattern is based in iterators:</p>
<ul>
<li>The first data set is specified by two iterators.</li>
<li>The output data set is specified by an iterator to the start of the output sequence.</li>
<li>All the other input data sets are specified by iterators to the start of the input data sequences. <hr/>
 <b>Example</b>: Computing the addition of three vectors. <div class="fragment"><div class="line">vector&lt;double&gt; v1 = get_first_vector();</div><div class="line">vector&lt;double&gt; v2 = get_second_vector();</div><div class="line">vector&lt;double&gt; v3 = get_third_vector();</div><div class="line">vector&lt;double&gt; w(v1.size());</div><div class="line"><a class="code" href="group__map__pattern__native.html#ga219611f3c6719598a8810d6ea6cafe2a">map</a>(exec, begin(v1), end(v1), begin(w),</div><div class="line">  [](<span class="keywordtype">double</span> x, <span class="keywordtype">double</span> y, <span class="keywordtype">double</span> z) { <span class="keywordflow">return</span> x+y+z; },</div><div class="line">  begin(v2), begin(v3)</div><div class="line">);</div></div><!-- fragment --><hr/>
 </li>
</ul>
</div></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.11
</small></address>
</body>
</html>
